﻿using System.Reflection;

namespace ExcelAutomator.Validation
{
	public class ReflectionValidator : BaseValidator
	{
		public object ValidationObject { get; private set; }
		public ValidationEngine ValidationEngine { get; private set; }

		public ReflectionValidator(object validationObject, ValidationEngine validationEngine)
		{
			ValidationObject = validationObject;
			ValidationEngine = validationEngine;
		}

		public ReflectionValidator PropertyValuesContainNot(string expression)
		{
			foreach (PropertyInfo property in ValidationObject.GetType().GetProperties())
			{
				var value = property.GetValue(ValidationObject, null);

				if (value != null)
				{
					if (!string.IsNullOrEmpty(value.ToString()))
					{
						ValidationEngine.Validate.That.String(value.ToString(), property.Name).ContainsNot(expression);
					}
				}
			}
			return this;
		}
	}
}
